﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SmsUI.DataBase;

namespace SmsUI
{
    public partial class ReciveListForm : DevExpress.XtraEditors.XtraUserControl
    {
        smsdbDataSet.tb_ReciveListDataTable tb = null;
        public ReciveListForm()
        {
            InitializeComponent();
            tb = DbRules.Instance.GetReciveListTable();
            this.grdRecive.DataSource = tb;

        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (DevExpress.XtraEditors.XtraMessageBox.Show("确认删除吗？", "删除 ", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation).Equals(DialogResult.OK))
            {
                int[] seleRow = this.gridView1.GetSelectedRows();
                for (int i = seleRow.Length - 1; i > -1; i--)
                {
                    tb[seleRow[i]].Delete();
                }
                DbRules.Instance.UpdateReciveList();
                tb.AcceptChanges();
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            if (DevExpress.XtraEditors.XtraMessageBox.Show("确认清空吗？", "清空 ", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation).Equals(DialogResult.OK))
            {
                for (int i = tb.Rows.Count - 1; i > -1; i--)
                {
                    tb.Rows[i].Delete();
                }
                DbRules.Instance.UpdateReciveList();
                tb.AcceptChanges();
            }
        }

        private void btnReley_Click(object sender, EventArgs e)
        {
            sendListForm sendForm = ((sendListForm)FormManager.Instance.GetForm("SendListItem"));

            int[] seleRow = this.gridView1.GetSelectedRows();
            if (seleRow.Length == 1)
            {
                RelayWin win = new RelayWin();
                win.Content = tb[seleRow[0]].Content;
                win.PortNum = tb[seleRow[0]].ReciveSet;
                win.ReciveNum = tb[seleRow[0]].PhoneNum;
                if (win.ShowDialog() == DialogResult.OK)
                {
                    sendForm.AddNum(win.ReciveNum, win.PortNum, win.Content);
                }
            }

        }

    }
}
